import java.util.Arrays;
public class MyList implements List {
    int[] array = new int[6];
    int NumberSize;

    MyList() {
        array[0] = 0;
        array[1] = 1;
        array[2] = 2;
        NumberSize = 3;
    }

    public boolean Full() {
        return this.NumberSize == array.length;
    }

    private void grow() {
        array = Arrays.copyOf(this.array, 2 * this.array.length);
    }

    @Override
    public void Add(int num) {
        if (Full())
            grow();
        array[NumberSize] = num;
        NumberSize++;
    }

    private void Judge(int pos) {
        if (pos < 0 || pos > NumberSize) {
            throw new RuntimeException("输入的位置有误");
           
        }
    }

    @Override
    public void Add(int pos, int num) {
        if (Full())
            grow();
        try {
            Judge(pos);
            for (int i = NumberSize; i >= pos; i--) {
                array[i + 1] = array[i];
            }
            array[pos] = num;
            NumberSize++;
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void Show() {
        for (int i = 0; i < NumberSize; i++){
            System.out.println(array[i]);
        }
    }

    private void Judge1(int pos) {
        if (pos < 0 || pos >= NumberSize)
            throw new RuntimeException("输入位置不合法，数组元素为个数为：+" + NumberSize);
    }

    @Override
    public int Find(int pos) {
        try {
            Judge1(pos);
        } catch (RuntimeException e) {
            e.printStackTrace();
        }
        return array[pos];
    }
    public int FindPos(int num){
        for (int i = 0; i <NumberSize ; i++) {
            if (array[i]==num){
                return i;
            }

        }
        return -1;
    }
    @Override
    public void Delete(int num) {
        int pos=FindPos(num);
        for (int i = pos; i <NumberSize ; i++) {
             array[i]=array[i+1];
        }
        NumberSize--;
    }
    @Override
    public void Modify(int pos, int num) {
      array[pos]=num;
    }
}
